package com.zhoug.zmui3.menu.tree;

import java.io.Serializable;
import java.util.List;
import java.util.Objects;

/**
 * 树形菜单节点
 * @Author 35574
 * @Date 2020/11/20
 * @Description
 */
public class TreeNode implements Serializable,ITreeNode {
    private String id;
    private String name;
    private List<TreeNode> child;
    private boolean hasChild;//是否有子节点,
    private boolean isExpanded;//是否展开

    public TreeNode() {

    }

    @Override
    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    @Override
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Override
    public List<TreeNode> getChild() {
        return child;
    }

    public void setChild(List<TreeNode> child) {
        this.child = child;
        if(child!=null && child.size()>0){
            hasChild=true;
        }
    }

    @Override
    public boolean isHasChild() {
        return hasChild;
    }

    @Override
    public void setHasChild(boolean hasChild) {
        this.hasChild = hasChild;
    }

    @Override
    public boolean isExpanded() {
        return isExpanded;
    }

    @Override
    public void setExpanded(boolean expanded) {
        isExpanded = expanded;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        TreeNode treeNode = (TreeNode) o;
        return Objects.equals(id, treeNode.id) &&
                Objects.equals(name, treeNode.name);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id, name);
    }

    @Override
    public String toString() {
        return "TreeNode{" +
                "id='" + id + '\'' +
                ", name='" + name + '\'' +
                ", hasChild=" + hasChild +
                '}';
    }
}
